Socket
Socket
Sign inDemoInstall

babel-plugin-jest-hoist

Package Overview
Dependencies
18
Maintainers
7
Versions
188
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-jest-hoist

Babel plugin to hoist `jest.disableAutomock`, `jest.enableAutomock`, `jest.unmock`, `jest.mock`, calls above `import` statements. This plugin is automatically included when using [babel-jest](https://github.com/facebook/jest/tree/master/packages/babel-jes


Version published
Maintainers
7
Install size
3.58 MB
Created

Package description

What is babel-plugin-jest-hoist?

The babel-plugin-jest-hoist npm package is designed to work with Jest, a popular JavaScript testing framework. It allows Jest to hoist `jest.mock`, `jest.unmock`, `jest.enableAutomock`, `jest.disableAutomock`, `jest.useFakeTimers`, `jest.useRealTimers`, `jest.setMock`, and `jest.clearAllMocks` calls to the top of the file. This is necessary because Jest needs to isolate modules for mocking before they are used in tests, and doing so manually can be error-prone and tedious.

What are babel-plugin-jest-hoist's main functionalities?

Hoisting jest.mock calls

Automatically hoists `jest.mock` calls to the top of the file, ensuring that modules are mocked before any other code execution.

"use strict";\njest.mock('moduleName');\nconsole.log('This is a test.');"

Hoisting jest.useFakeTimers calls

Automatically hoists `jest.useFakeTimers` calls to the top, allowing tests to use fake timers from the start.

"use strict";\njest.useFakeTimers();\nconsole.log('This is a test with fake timers.');"

Other packages similar to babel-plugin-jest-hoist

Changelog

Source

25.5.0

Features

  • [@jest/globals] New package so Jest's globals can be explicitly imported (#9801)
  • [jest-core] Show coverage of sources related to tests in changed files (#9769)
  • [jest-runtime] Populate require.cache (#9841)

Fixes

  • [*] Use graceful-fs directly in every package instead of relying on fs being monkey patched (#9443)
  • [expect] Prints the Symbol name into the error message with a custom asymmetric matcher (#9888)
  • [jest-circus, jest-jasmine2] Support older version of jest-runtime (#9903 & #9842)
  • [@jest/environment] Make sure not to reference Jest types (#9875)
  • [jest-message-util] Code frame printing should respect --noStackTrace flag (#9866)
  • [jest-runtime] Support importing CJS from ESM using import statements (#9850)
  • [jest-runtime] Support importing parallel dynamic imports (#9858)
  • [jest-transform] Improve source map handling when instrumenting transformed code (#9811)

Chore & Maintenance

  • [docs] Add an example for mocking non-default export class

Performance

  • [jest-resolve] Update resolve to a version using native realpath, which is faster than the default JS implementation (#9872)
  • [jest-resolve] Pass custom cached realpath function to resolve (#9873)
  • [jest-runtime] Add teardown method to clear any caches when tests complete (#9906)
  • [jest-runtime] Do not pass files required internally through transformation when loading them (#9900)
  • [jest-runtime] Use Maps instead of object literals as cache holders (#9901)

Readme

Source

babel-plugin-jest-hoist

Babel plugin to hoist jest.disableAutomock, jest.enableAutomock, jest.unmock, jest.mock, calls above import statements. This plugin is automatically included when using babel-jest.

Installation

$ yarn add --dev babel-plugin-jest-hoist

Usage

module.exports = {
  plugins: ['jest-hoist'],
};

Via CLI

$ babel --plugins jest-hoist script.js

Via Node API

require('@babel/core').transform('code', {
  plugins: ['jest-hoist'],
});

FAQs

Last updated on 28 Apr 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc